﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DevComponents.AdvTree;
using SyncLib;
using AppCommon;
using AppCommon.SyncConfigDSTableAdapters;

namespace SyncApplication
{
    public class ClientAdvTreeManipulation
    {
        public const int EnableScopeIndexKey = 2;
        public const int DisableScopeIndexKey = 3;
        public const int TableIndexKey = 4;
        public const int DepenIndexKey = 5;
        public const int FileIndexKey = 7;
        public const int ClientIndexKey = 7;
        public const int HistoryIndexKey = 9;

        public const string CommonScopeName = "CommonScope";
        public const string PrivateScopeName = "PrivateScope";
        public const string SyncScopeHistoryName = "SyncScopeHistory";
        public const string DependencyTableName = "DependencyTable";
        public const string TableOfScopeName = "TableOfScope";
        public const string ClientListName = "ClientsNode";
        public const string SummaryHistoryNodeName = "SummaryHistoryNode";
        public const string SynchronizeNodeName = "Synchronize";
        public const string OptionNodeName = "Option";
        public const string HistoryNodeName = "History";
        public const string ScopeRootNodeName = "ScopeRoot";

        public SyncConfigDS SyncConfig { get; set; }
        public ClientConfigTableAdapter AdapterClientConfigTable;
        public ScopeInfoExTableAdapter AdapterScopeInfoxExTable;
        public AdvTree Tree;
        public ClientAdvTreeManipulation(AdvTree tree)
        {
            Tree = tree;
            SyncConfig = new SyncConfigDS();
            AdapterClientConfigTable = new ClientConfigTableAdapter();
            AdapterClientConfigTable.Connection.ConnectionString = CommonVariable.SqlConnectionString;

            AdapterScopeInfoxExTable = new ScopeInfoExTableAdapter();
            AdapterScopeInfoxExTable.Connection.ConnectionString = CommonVariable.SqlConnectionString;

        }

        public void LoadData()
        {
            SyncConfig.Clear();
            AdapterClientConfigTable.Fill(SyncConfig.ClientConfig);
            AdapterScopeInfoxExTable.Fill(SyncConfig.ScopeInfoEx);
        }
        public void BuildTree()
        {
            Tree.Nodes.Clear();
            Node scopeNode = new Node();
            scopeNode.Text = "Danh sách phạm vi";
            scopeNode.Name = "ScopeRoot";
            scopeNode.ImageIndex = 0;
            Tree.Nodes.Add(scopeNode);
            foreach (SyncConfigDS.ScopeInfoExRow scopeRow in SyncConfig.ScopeInfoEx)
            {
                Node node = new Node();
                node.Text = scopeRow.ScopeName;
                node.ImageIndex= EnableScopeIndexKey;//:AdvTreeManipulation.DisableScopeIndexKey;
                scopeNode.Nodes.Add(node);
                node.Tag = scopeRow;
            }

            Node synchronizeNode = new Node("Đồng bộ");
            synchronizeNode.Name = "Synchronize";
            Tree.Nodes.Add(synchronizeNode);


            Node history = new Node("Lịch sử");
            history.Name = "History";
            Tree.Nodes.Add(history);

            Node config = new Node("Tùy chọn");
            config.Name = "Option";
            Tree.Nodes.Add(config);


        }


    }
}
